﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Pharmacy.Entities;
using Pharmacy.Data;

#endregion

namespace Pharmacy.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="ImportPoDetailsProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class ImportPoDetailsProviderBaseCore : EntityViewProviderBase<ImportPoDetails>
	{
		#region Custom Methods
		
		
		#region _ImportPODetails_GetByGRNId
		
		/// <summary>
		///	This method wrap the '_ImportPODetails_GetByGRNId' stored procedure. 
		/// </summary>
		/// <param name="grnId"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByGRNId(System.String grnId)
		{
			return GetByGRNId(null, 0, int.MaxValue , grnId);
		}
		
		/// <summary>
		///	This method wrap the '_ImportPODetails_GetByGRNId' stored procedure. 
		/// </summary>
		/// <param name="grnId"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByGRNId(int start, int pageLength, System.String grnId)
		{
			return GetByGRNId(null, start, pageLength , grnId);
		}
				
		/// <summary>
		///	This method wrap the '_ImportPODetails_GetByGRNId' stored procedure. 
		/// </summary>
		/// <param name="grnId"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetByGRNId(TransactionManager transactionManager, System.String grnId)
		{
			return GetByGRNId(transactionManager, 0, int.MaxValue , grnId);
		}
		
		/// <summary>
		///	This method wrap the '_ImportPODetails_GetByGRNId' stored procedure. 
		/// </summary>
		/// <param name="grnId"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet GetByGRNId(TransactionManager transactionManager, int start, int pageLength, System.String grnId);
		
		#endregion

		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;ImportPoDetails&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;ImportPoDetails&gt;"/></returns>
		protected static VList&lt;ImportPoDetails&gt; Fill(DataSet dataSet, VList<ImportPoDetails> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<ImportPoDetails>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;ImportPoDetails&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<ImportPoDetails>"/></returns>
		protected static VList&lt;ImportPoDetails&gt; Fill(DataTable dataTable, VList<ImportPoDetails> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					ImportPoDetails c = new ImportPoDetails();
					c.PoId = (Convert.IsDBNull(row["POId"]))?string.Empty:(System.String)row["POId"];
					c.DrugId = (Convert.IsDBNull(row["DrugId"]))?string.Empty:(System.String)row["DrugId"];
					c.Quantity = (Convert.IsDBNull(row["Quantity"]))?(int)0:(System.Int32)row["Quantity"];
					c.RemainQuantity = (Convert.IsDBNull(row["RemainQuantity"]))?(int)0:(System.Int32)row["RemainQuantity"];
					c.Remark = (Convert.IsDBNull(row["Remark"]))?string.Empty:(System.String)row["Remark"];
					c.PoDetailId = (Convert.IsDBNull(row["PODetailId"]))?(long)0:(System.Int64)row["PODetailId"];
					c.DrugName = (Convert.IsDBNull(row["DrugName"]))?string.Empty:(System.String)row["DrugName"];
					c.Unit = (Convert.IsDBNull(row["Unit"]))?string.Empty:(System.String)row["Unit"];
					c.CostPrice = (Convert.IsDBNull(row["CostPrice"]))?0.0m:(System.Decimal)row["CostPrice"];
					c.SellPrice = (Convert.IsDBNull(row["SellPrice"]))?0.0m:(System.Decimal)row["SellPrice"];
					c.MarkUpPercent = (Convert.IsDBNull(row["MarkUpPercent"]))?0.0m:(System.Decimal)row["MarkUpPercent"];
					c.MarkUpName = (Convert.IsDBNull(row["MarkUpName"]))?string.Empty:(System.String)row["MarkUpName"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;ImportPoDetails&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;ImportPoDetails&gt;"/></returns>
		protected VList<ImportPoDetails> Fill(IDataReader reader, VList<ImportPoDetails> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					ImportPoDetails entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<ImportPoDetails>("ImportPoDetails",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new ImportPoDetails();
					}
					
					entity.SuppressEntityEvents = true;

					entity.PoId = (System.String)reader[((int)ImportPoDetailsColumn.PoId)];
					//entity.PoId = (Convert.IsDBNull(reader["POId"]))?string.Empty:(System.String)reader["POId"];
					entity.DrugId = (System.String)reader[((int)ImportPoDetailsColumn.DrugId)];
					//entity.DrugId = (Convert.IsDBNull(reader["DrugId"]))?string.Empty:(System.String)reader["DrugId"];
					entity.Quantity = (System.Int32)reader[((int)ImportPoDetailsColumn.Quantity)];
					//entity.Quantity = (Convert.IsDBNull(reader["Quantity"]))?(int)0:(System.Int32)reader["Quantity"];
					entity.RemainQuantity = (System.Int32)reader[((int)ImportPoDetailsColumn.RemainQuantity)];
					//entity.RemainQuantity = (Convert.IsDBNull(reader["RemainQuantity"]))?(int)0:(System.Int32)reader["RemainQuantity"];
					entity.Remark = (reader.IsDBNull(((int)ImportPoDetailsColumn.Remark)))?null:(System.String)reader[((int)ImportPoDetailsColumn.Remark)];
					//entity.Remark = (Convert.IsDBNull(reader["Remark"]))?string.Empty:(System.String)reader["Remark"];
					entity.PoDetailId = (System.Int64)reader[((int)ImportPoDetailsColumn.PoDetailId)];
					//entity.PoDetailId = (Convert.IsDBNull(reader["PODetailId"]))?(long)0:(System.Int64)reader["PODetailId"];
					entity.DrugName = (System.String)reader[((int)ImportPoDetailsColumn.DrugName)];
					//entity.DrugName = (Convert.IsDBNull(reader["DrugName"]))?string.Empty:(System.String)reader["DrugName"];
					entity.Unit = (System.String)reader[((int)ImportPoDetailsColumn.Unit)];
					//entity.Unit = (Convert.IsDBNull(reader["Unit"]))?string.Empty:(System.String)reader["Unit"];
					entity.CostPrice = (System.Decimal)reader[((int)ImportPoDetailsColumn.CostPrice)];
					//entity.CostPrice = (Convert.IsDBNull(reader["CostPrice"]))?0.0m:(System.Decimal)reader["CostPrice"];
					entity.SellPrice = (System.Decimal)reader[((int)ImportPoDetailsColumn.SellPrice)];
					//entity.SellPrice = (Convert.IsDBNull(reader["SellPrice"]))?0.0m:(System.Decimal)reader["SellPrice"];
					entity.MarkUpPercent = (System.Decimal)reader[((int)ImportPoDetailsColumn.MarkUpPercent)];
					//entity.MarkUpPercent = (Convert.IsDBNull(reader["MarkUpPercent"]))?0.0m:(System.Decimal)reader["MarkUpPercent"];
					entity.MarkUpName = (System.String)reader[((int)ImportPoDetailsColumn.MarkUpName)];
					//entity.MarkUpName = (Convert.IsDBNull(reader["MarkUpName"]))?string.Empty:(System.String)reader["MarkUpName"];
					entity.AcceptChanges();
					entity.SuppressEntityEvents = false;
					
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="ImportPoDetails"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="ImportPoDetails"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, ImportPoDetails entity)
		{
			reader.Read();
			entity.PoId = (System.String)reader[((int)ImportPoDetailsColumn.PoId)];
			//entity.PoId = (Convert.IsDBNull(reader["POId"]))?string.Empty:(System.String)reader["POId"];
			entity.DrugId = (System.String)reader[((int)ImportPoDetailsColumn.DrugId)];
			//entity.DrugId = (Convert.IsDBNull(reader["DrugId"]))?string.Empty:(System.String)reader["DrugId"];
			entity.Quantity = (System.Int32)reader[((int)ImportPoDetailsColumn.Quantity)];
			//entity.Quantity = (Convert.IsDBNull(reader["Quantity"]))?(int)0:(System.Int32)reader["Quantity"];
			entity.RemainQuantity = (System.Int32)reader[((int)ImportPoDetailsColumn.RemainQuantity)];
			//entity.RemainQuantity = (Convert.IsDBNull(reader["RemainQuantity"]))?(int)0:(System.Int32)reader["RemainQuantity"];
			entity.Remark = (reader.IsDBNull(((int)ImportPoDetailsColumn.Remark)))?null:(System.String)reader[((int)ImportPoDetailsColumn.Remark)];
			//entity.Remark = (Convert.IsDBNull(reader["Remark"]))?string.Empty:(System.String)reader["Remark"];
			entity.PoDetailId = (System.Int64)reader[((int)ImportPoDetailsColumn.PoDetailId)];
			//entity.PoDetailId = (Convert.IsDBNull(reader["PODetailId"]))?(long)0:(System.Int64)reader["PODetailId"];
			entity.DrugName = (System.String)reader[((int)ImportPoDetailsColumn.DrugName)];
			//entity.DrugName = (Convert.IsDBNull(reader["DrugName"]))?string.Empty:(System.String)reader["DrugName"];
			entity.Unit = (System.String)reader[((int)ImportPoDetailsColumn.Unit)];
			//entity.Unit = (Convert.IsDBNull(reader["Unit"]))?string.Empty:(System.String)reader["Unit"];
			entity.CostPrice = (System.Decimal)reader[((int)ImportPoDetailsColumn.CostPrice)];
			//entity.CostPrice = (Convert.IsDBNull(reader["CostPrice"]))?0.0m:(System.Decimal)reader["CostPrice"];
			entity.SellPrice = (System.Decimal)reader[((int)ImportPoDetailsColumn.SellPrice)];
			//entity.SellPrice = (Convert.IsDBNull(reader["SellPrice"]))?0.0m:(System.Decimal)reader["SellPrice"];
			entity.MarkUpPercent = (System.Decimal)reader[((int)ImportPoDetailsColumn.MarkUpPercent)];
			//entity.MarkUpPercent = (Convert.IsDBNull(reader["MarkUpPercent"]))?0.0m:(System.Decimal)reader["MarkUpPercent"];
			entity.MarkUpName = (System.String)reader[((int)ImportPoDetailsColumn.MarkUpName)];
			//entity.MarkUpName = (Convert.IsDBNull(reader["MarkUpName"]))?string.Empty:(System.String)reader["MarkUpName"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="ImportPoDetails"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="ImportPoDetails"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, ImportPoDetails entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.PoId = (Convert.IsDBNull(dataRow["POId"]))?string.Empty:(System.String)dataRow["POId"];
			entity.DrugId = (Convert.IsDBNull(dataRow["DrugId"]))?string.Empty:(System.String)dataRow["DrugId"];
			entity.Quantity = (Convert.IsDBNull(dataRow["Quantity"]))?(int)0:(System.Int32)dataRow["Quantity"];
			entity.RemainQuantity = (Convert.IsDBNull(dataRow["RemainQuantity"]))?(int)0:(System.Int32)dataRow["RemainQuantity"];
			entity.Remark = (Convert.IsDBNull(dataRow["Remark"]))?string.Empty:(System.String)dataRow["Remark"];
			entity.PoDetailId = (Convert.IsDBNull(dataRow["PODetailId"]))?(long)0:(System.Int64)dataRow["PODetailId"];
			entity.DrugName = (Convert.IsDBNull(dataRow["DrugName"]))?string.Empty:(System.String)dataRow["DrugName"];
			entity.Unit = (Convert.IsDBNull(dataRow["Unit"]))?string.Empty:(System.String)dataRow["Unit"];
			entity.CostPrice = (Convert.IsDBNull(dataRow["CostPrice"]))?0.0m:(System.Decimal)dataRow["CostPrice"];
			entity.SellPrice = (Convert.IsDBNull(dataRow["SellPrice"]))?0.0m:(System.Decimal)dataRow["SellPrice"];
			entity.MarkUpPercent = (Convert.IsDBNull(dataRow["MarkUpPercent"]))?0.0m:(System.Decimal)dataRow["MarkUpPercent"];
			entity.MarkUpName = (Convert.IsDBNull(dataRow["MarkUpName"]))?string.Empty:(System.String)dataRow["MarkUpName"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region ImportPoDetailsFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ImportPoDetails"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ImportPoDetailsFilterBuilder : SqlFilterBuilder<ImportPoDetailsColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ImportPoDetailsFilterBuilder class.
		/// </summary>
		public ImportPoDetailsFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ImportPoDetailsFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ImportPoDetailsFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ImportPoDetailsFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ImportPoDetailsFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ImportPoDetailsFilterBuilder

	#region ImportPoDetailsParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ImportPoDetails"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ImportPoDetailsParameterBuilder : ParameterizedSqlFilterBuilder<ImportPoDetailsColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ImportPoDetailsParameterBuilder class.
		/// </summary>
		public ImportPoDetailsParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ImportPoDetailsParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ImportPoDetailsParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ImportPoDetailsParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ImportPoDetailsParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ImportPoDetailsParameterBuilder
	
	#region ImportPoDetailsSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ImportPoDetails"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class ImportPoDetailsSortBuilder : SqlSortBuilder<ImportPoDetailsColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ImportPoDetailsSqlSortBuilder class.
		/// </summary>
		public ImportPoDetailsSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion ImportPoDetailsSortBuilder

} // end namespace
